package cn.gson.crm.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gson.crm.model.dao.LLJ_CareTypeDao;
import cn.gson.crm.model.dao.LLJ_ComplainDao;
import cn.gson.crm.model.dao.LLJ_CustomerCareDao;
import cn.gson.crm.model.dao.LLJ_CustomerinfoDao;
import cn.gson.crm.model.pojo.CareType;
import cn.gson.crm.model.pojo.CustomerCare;
import cn.gson.crm.model.pojo.Customerinfo;
  
@Service
@Transactional(rollbackFor = Exception.class)
public class LLJ_CustomerCareService {  
	@Autowired
	private LLJ_CustomerCareDao llj_CustomerCareDao;
	@Autowired
	private LLJ_CareTypeDao careTypeDao;
	@Autowired
	private LLJ_CustomerinfoDao CustomerinfoDao; 
	
	/* 客户关怀表 */
	
	public long count(){ 
		return llj_CustomerCareDao.count();  
	}
	
	/**
	 * 分页查询   
	 */
	public List<CustomerCare> getAllCustomerCarePages(int page,int rows){
		PageRequest p=new PageRequest(page-1, rows); 
		List<CustomerCare> list=llj_CustomerCareDao.findByPage(p);     
		
		return list;
		
	}
	
	
	
	public long countByTheme(String key){
		return llj_CustomerCareDao.countByCcTheme('%'+key+'%');
	}   
	
	/**
	 * 分页查询_by_theme(无分页显示)
	 * @return
	 */
	public List<CustomerCare> getAllCustomerCarePagesByTheme(String key){	
		return llj_CustomerCareDao.queryFindAllByCcTheme('%'+key+'%');      
		    
	}
	/**
	 * 添加客户关怀数据      
	 * @return
	 */
	public boolean addOne_data_CustomerCare(CustomerCare cc){
		boolean judge=false;
		try {
			CustomerCare cust=new CustomerCare(cc.getCcContent(),
					cc.getCcCreationTime(), cc.getCcExecutor(), 
					cc.getCcFeedback(), cc.getCcLinkMan(), 
					cc.getCcRemarks(), cc.getCcTheme(), 
					cc.getCustomerName());
			llj_CustomerCareDao.save(cc); 
			judge=true;
		} catch (Exception e) {
			judge=false;
		}   
		return judge;	   	
	}
	/**
	 * 编辑客户关怀数据
	 */
	public boolean editData(CustomerCare cc){
		try {
			Long ccId=cc.getCcId();
			llj_CustomerCareDao.findOne(ccId);
			llj_CustomerCareDao.save(cc);  
			return true;  
		} catch (Exception e) {
			return false;  
		}  
	}
	
	
	/**
	 * 查询客户关怀数据2
	 */
	public List<CustomerCare> searchAll(){
		
		return (List<CustomerCare>) llj_CustomerCareDao.findAll();
	}  
	
	
	/**
	 * 通过客户关怀id删除数据
	 * @return
	 * @throws Exception 
	 */
	public boolean deleteOneDate(Long ccId) throws Exception{
		boolean judge=false;
		System.out.println("进入业务类--------------------------");
		System.out.println(ccId);
		try {
			CustomerCare cc=new CustomerCare();
			cc=llj_CustomerCareDao.findOne(ccId);  
			llj_CustomerCareDao.delete(cc);     
			judge=true;  
		} catch (Exception e) {
			judge=false;
		}
		return judge;             
	}
	
	/**
	 * 通过客户关怀id查询数据
	 * @return
	 */
	public CustomerCare getCustomerData(Long CC_id){
		CustomerCare cus=new CustomerCare();
		cus=llj_CustomerCareDao.queryFindAll_CC_id(CC_id);
		return cus;            
	}
	           
	/**
	 * 户关怀类型表 
	 */
	public List<CareType> findCareTypeData(){
		return (List<CareType>) careTypeDao.findCareTypeDate();
	}  
	
	/**
	 * 查询客户信息
	 */
	public List<Customerinfo> serchAllCustomer(){
		
		return CustomerinfoDao.searchAllData();
		  
	}
	
	
	
	

}
